package com.songcha.library_common.util

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import com.songcha.library_common.BuildConfig


class PackageUtil {
    companion object{

        @JvmStatic
        fun getPackageName(context: Context):String{
            val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0);
            return packageInfo.packageName
        }

        @JvmStatic
        fun getPackageVersionCode(context: Context):Int{
            val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0);
            return packageInfo.versionCode
        }

        @JvmStatic
        fun getPackageVersionName(context: Context):String{
            val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0);
            return packageInfo.versionName
        }

        @JvmStatic
        fun getUmengChannelName(context: Context):String{
            try {
                val pm: PackageManager = context.packageManager
                val appInfo = pm.getApplicationInfo(
                    getPackageName(context),
                    PackageManager.GET_META_DATA
                )
                if(appInfo.metaData==null) return ""
                return appInfo.metaData.getString("UMENG_CHANNEL")?:""
            } catch (e: PackageManager.NameNotFoundException) {
                e.printStackTrace()
            }
            return ""
        }

        @JvmStatic
        fun getAppName(context: Context):String{
            try {
                val applicationInfo = context.applicationInfo
                val appName = context.packageManager.getApplicationLabel(applicationInfo).toString()
                return appName
            } catch (e: PackageManager.NameNotFoundException) {
                e.printStackTrace()
            }
            return ""
        }

    }


}